import { Cloud } from 'laf-client-sdk'
import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()
const cloud = new Cloud({
  baseUrl: 'https://su75ks.laf.run', // <APP_ID> 在首页应用列表获取
  getAccessToken: () => userStore.token, // 这里不需要授权，先填空
})

//获取一个人的所有私发消息
export async function getNotice() {
  const res = await cloud.invoke('curd_op', {
    collection: 'PB_Inf',
    operation: 'get',
    data: {
      where: {
        utype: 2,
      },
      orderBy: {
        create_time: 'desc',
      },
    },
  })
  const count = await cloud.invoke('curd_op', {
    collection: 'PB_Inf',
    operation: 'count',
    data: {
      where: {
        utype: 2,
      },
    },
  })

  return { res, count }
}

//获取一条通知的发送者，接收者
export async function getNoticeSR(_id) {
  const res = await cloud.invoke('curd_op', {
    collection: 'PB_Inf',
    operation: 'get',
    data: {
      where: {
        _id: _id,
      },
    },
  })
  return res
}
